package com.topvision.controller.region;

import java.util.List;
import java.util.Map;

import com.topvision.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.topvision.model.region.Region;
import com.topvision.service.region.RegionService;
import com.topvision.util.PageUtils;
import com.topvision.util.Query;
import com.topvision.util.R;

/**
 * 区域数据表
 *
 * @author shengwm
 * @email 179653076@qq.com
 * @date 2017-08-30 14:44:04
 */
@RestController
@RequestMapping("region/region")
public class RegionController extends AbstractController {
    @Autowired
    private RegionService regionService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("region/region:list")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        Query query = new Query(params);

        List<Region> regionList = regionService.queryList(query);
        int total = regionService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(regionList, total, query.getLimit(), query.getPage());

        return R.success().put("page", pageUtil);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("region/region:info")
    public R info(@PathVariable("id") Integer id){
        Region region = regionService.queryObject(id);
        return R.success().put("region", region);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("region/region:save")
    public R save(@RequestBody Region region){
		regionService.save(region);
        return R.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("region/region:update")
    public R update(@RequestBody Region region){
		regionService.update(region);
        return R.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("region/region:delete")
    public R delete(@RequestBody Integer[] ids){
		regionService.deleteBatch(ids);
        return R.success();
    }

    /**
     * 所有城市数据
     */
    @RequestMapping("/regionlist")
    public R regionlist(){
        List<Region> regionList = regionService.findAll();
        return R.success().put("region",regionList);
    }

}
